const Controller = require("egg").Controller;

class StudendController extends Controller {
    async index() {
        let list = await this.service.student.getStudentList()
        if (list) {
            this.ctx.body = {
                code: 20000,
                data: list
            }
        } else {
            this.ctx.body = {
                code: 50000,
                msg: "服务器异常，请与管理员联系。"
            }
        }
        this.ctx.body = list;
    }
    async create() {
        let name = this.ctx.request.body.name;
        let achievement = this.ctx.request.body.achievement;
        let clazz_id = this.ctx.request.body.clazz_id;
        let result = await this.ctx.service.student.createStudent(name, achievement, clazz_id)
        if (result) {
            this.ctx.body = {
                code: 2000,
                msg: "添加成功"
            }
        } else {
            this.ctx.body = {
                code: 50000,
                msg: "添加失败"
            }
        }
        this.ctx.body = "添加成功"
    }
    async destroy() {
        let id = this.ctx.params.id;
        let del = await this.ctx.service.student.destroyStudent(id)
        if(del){
            this.ctx.body = {
                code:20000,
                msg:"删除成功"
            }
        }else{
            this.ctx.body = {
                code:50000,
                msg:"删除失败"
            }
        }
        console.log(id)
        this.ctx.body = "删除成功！"
    }
}

module.exports = StudendController;